﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command;
using MediatR;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler
{
    public class FanTianRoleCommandHandler : IRequestHandler<FanTianRoleCommand, APIResult<List<Role>>>
    {
        private readonly IBaseRepository<Role> roleRep;

        public FanTianRoleCommandHandler(IBaseRepository<Role> roleRep)
        {
            this.roleRep = roleRep;
        }

        public  Task<APIResult<List<Role>>> Handle(FanTianRoleCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Role>> result = new APIResult<List<Role>>();
            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();

            var list = roleRep.GetAll().Where(x => x.RoleId == request.RoleId);
            result.data = list.ToList();
            return  Task.FromResult(result);
        }

    }
}
